#include "InputManager.h"

InputManager::~InputManager()
{
	
}

void InputManager::Clean()
{
	// release the input manager object
	m_pKeyboardDevice->Unacquire();
	m_pKeyboardDevice->Release();
	m_pKeyboardDevice = NULL;
	m_pInputManager->Release();
	m_pInputManager = NULL;

}

bool InputManager::InitInputManager()
{
	if(FAILED(DirectInput8Create(GetModuleHandle(NULL),
		DIRECTINPUT_VERSION,
		IID_IDirectInput8,
		(void**)&m_pInputManager,
		NULL)))
	{
		return false;
	}
	return true;
}

bool InputManager::InitKeyboard()
{
	if(FAILED(m_pInputManager->CreateDevice(GUID_SysKeyboard, &m_pKeyboardDevice, NULL)))
	{
		return false;
	}

	if(FAILED(m_pKeyboardDevice->SetDataFormat(&c_dfDIKeyboard)))
	{
		return false;
	}

	if(FAILED(m_pKeyboardDevice->SetCooperativeLevel(TheD3DApp::Instance()->GetWindowHandle(), DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))
	{
		return false;
	}

	if(FAILED(m_pKeyboardDevice->Acquire()))
	{
		return false;
	}

	return true;
}
bool InputManager::Update()
{
	if(FAILED(m_pKeyboardDevice->GetDeviceState(sizeof(m_keyBuffer),(LPVOID)&m_keyBuffer)))
	{
		return false;
	}
	return false;
}

bool InputManager::KeyPressed(int Key)
{
	if(m_keyBuffer[Key] & 0x80)
	{
		return true;
	}

	return false;
}
